/*
 * tss.cpp
 *
 *  Created on: 2008-9-21
 *      Author: ant
 */

#include "tss.h"

#if defined(PLATFORM_WIN32)

#include <windows.h>

BEGIN_NAMESPACE_TOXIC

namespace detail {

	void tss::cleanup() {
		IndexCleanupMap& _map = tssMap();
		IndexCleanupMap::const_iterator it(_map.begin()), end(_map.end());
		for ( ; it != end; ++it) {
			cleanup_route cleanup = it->second;
			if (cleanup != 0) {
				void* value = TlsGetValue(it->first);
				if (value != 0) {
					cleanup(value);
				}
			}
		}
	}

	IndexCleanupMap& tss::tssMap() {
		static IndexCleanupMap _tssMap;
		return _tssMap;
	}

} // namespace detail

END_NAMESPACE_TOXIC

#endif
